//
//  MoonSelectView.m
//  SportRing
//
//  Created by 微我网络 on 15/1/26.
//  Copyright (c) 2015年 HotOne. All rights reserved.
//

#import "MoonSelectView.h"

@interface MoonSelectView ()

@property (nonatomic) NSMutableArray *moons;

@end

@implementation MoonSelectView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
//        self.backgroundColor = [UIColor redColor];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 20)];
        label.font = [UIFont systemFontOfSize:10];
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"睡眠质量";
        label.hidden = YES;
        label.center = CGPointMake(CGRectGetWidth(self.frame)/2, 50);
        [self addSubview:label];
        
        for (int i = 0; i < 5; i++) {
            UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"moons"]];
            imageView.frame = CGRectMake((self.frame.size.width-160)/2+2+i*34, 0, 22, 22);
            [self addSubview:imageView];
        }
        
        _moons = [NSMutableArray array];
    }
    return self;
}

- (void)setNumber:(NSInteger)number {
    
    if (number > 5||number < 0) {
        return;
    }
    
    for (UIImageView *img in _moons) {
        [img removeFromSuperview];
    }
    [_moons removeAllObjects];
    
    for (int i = 0; i < number; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fullmoon"]];
        imageView.frame = CGRectMake((self.frame.size.width-160)/2+2+i*34, 0, 22, 22);
        [self addSubview:imageView];
        [_moons addObject:imageView];
    }
}

- (NSInteger)number {
    
    return [_moons count];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
